<template>
  <div class="app-container home">    
    <el-row :gutter="20">
      <el-col :sm="24" :lg="12" style="padding-left: 20px">
        <h2>千丝SDN控制器</h2>
        <p>
          本项目是一个基于SDN（软件定义网络）与区块链技术的智能网络管理系统。系统通过流表管理中心实现动态流量控制，并利用区块链对流表操作进行存证，确保数据透明性和防篡改性。包含流量监控、拓扑可视化、RBAC权限管理等模块。
        </p>
       
      </el-col>

      <el-col :sm="24" :lg="12" style="padding-left: 50px">
        <el-row>
          <el-col :span="12">
            <h2>技术选型</h2>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <h4>后端技术</h4>
            <ul>
              <li>Go</li>
              <li>Gin</li>
              <li>JWT</li>
              <li>gorm</li>
              <li>copier</li>
              <li>xxl-job</li>
              <li>...</li>
            </ul>
          </el-col>
          <el-col :span="6">
            <h4>前端技术</h4>
            <ul>
              <li>Vue</li>
              <li>Vuex</li>
              <li>Element-ui</li>
              <li>Axios</li>
              <li>Sass</li>
              <li>Quill</li>
              <li>...</li>
            </ul>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
    <el-divider />
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :md="12" :lg="8">
      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="8">
        <el-card class="update-log">
          <div slot="header" class="clearfix">
            <h2>更新日志</h2>
          </div>
          <el-collapse accordion>             
            <el-collapse-item title="v1.0.0 - 2025-03-02">
              <ol>
                <li>项目初始化 维护者：夏振东</li>
              </ol>
            </el-collapse-item>
            <el-collapse-item title="v1.1.0 - 2025-04-06">
              <ol>
                <li>主体开发 维护者：夏振东</li>
              </ol>
            </el-collapse-item>
            <el-collapse-item title="v1.2.0 - 2025-04-21">
              <ol>
                <li>完善平台 维护者：夏振东</li>
              </ol>
            </el-collapse-item>
          </el-collapse>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="8">
        <el-card class="update-log">
          <div slot="header" class="clearfix">
            <h2>AI助手</h2>
          </div>
          <div class="ai-container">
          
          <el-input v-model="aiQuestion" placeholder="有什么网络方面的疑问找我聊聊吧~" :disabled="isAILoading"
            @keyup.enter.native="askAI">
            <template #append>
              <el-button icon="el-icon-s-promotion" @click="askAI" :loading="isAILoading">发送</el-button>
            </template>
          </el-input>
          <div class="ai-history">
            <div v-for="(msg, index) in conversationHistory" :key="index"
              :class="{ 'user-msg': msg.role === 'user', 'ai-msg': msg.role === 'assistant' }">
              {{ msg.content }}
            </div>
          </div>
        </div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="8">
        <el-card class="update-log">
          <div slot="header" class="clearfix">
            <h2>异常记录</h2>
          </div>
          <el-collapse accordion>             
            <el-collapse-item title="2025-03-02">
              <ol>
                <li>S1流量异常</li>
              </ol>
            </el-collapse-item>
            <el-collapse-item title="2025-03-02">
              <ol>
                <li>上链失败</li>
              </ol>
            </el-collapse-item>
            <el-collapse-item title="2025-03-02">
              <ol>
                <li>上链失败</li>
              </ol>
            </el-collapse-item>
            <el-collapse-item title="2025-03-03">
              <ol>
                <li>上链失败</li>
              </ol>
            </el-collapse-item>
            <el-collapse-item title="2025-03-03">
              <ol>
                <li>上链失败</li>
              </ol>
            </el-collapse-item>
            <el-collapse-item title="2025-03-04">
              <ol>
                <li>上链失败</li>
              </ol>
            </el-collapse-item>
          </el-collapse>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: "Index",
  data() {
    return {
      // 版本号
      version: "1.0.0",
      aiQuestion: '',
      aiAnswer: '有什么网络方面的疑问找我聊聊吧~',
      isAILoading: false,
      conversationHistory: []
    };
  },
  methods: {
    goTarget(href) {
      window.open(href, "_blank");
    },
    async askAI() {
      if (!this.aiQuestion.trim()) return;

      try {
        this.isAILoading = true;
        this.conversationHistory.push({ role: 'user', content: this.aiQuestion });

        const response = await axios.post(
          'https://ark.cn-beijing.volces.com/api/v3/chat/completions',
          {
            model: "doubao-1-5-lite-32k-250115",
            messages: [
              {
                role: "system",
                content: "你是一个专业的网络工程师，用中文回答用户关于网络的问题。回答要简洁易懂，例举命令代码，分为华为，思科，H3C的。"
              },
              ...this.conversationHistory
            ],
            temperature: 0.3,
            max_tokens: 1000
          },
          {
            headers: {
              'Content-Type': 'application/json',
              'Authorization': `Bearer 26922af0-34d9-48e9-a5d8-7ed86a2b8aa8`
            }
          }
        );

        const aiResponse = response.data.choices[0].message.content;
        this.conversationHistory.push({ role: 'assistant', content: aiResponse });
        this.aiAnswer = aiResponse;
        this.aiQuestion = '';
      } catch (error) {
        this.aiAnswer = 'AI服务请求失败，请检查网络连接';
        console.error('AI请求错误:', error);
      } finally {
        this.isAILoading = false;
      }
    },
    //切换样式
    switchStyles(e) {
      if (this.content_nocard == false) {
        this.content_nocard = true
        this.content = false
      } else {
        this.content = true
        this.content_nocard = false
        this.content_nocard = false
      }

    },
    //弹框
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => { });
    },

    async queryDatabase(query) {
      try {
        // 准备查询
        const stmt = this.db.prepare(query);

        // 获取查询结果
        const results = stmt.getAsObject();

        // 输出查询结果
        console.log(results);
      } catch (error) {
        console.error('Error executing query:', error);
      }
    }
  },
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }

  .ai-history {
  height: 400px;
  margin-bottom: 15px;
  padding: 10px;
  border: 1px solid #ebeef5;
  border-radius: 4px;
  overflow-y: auto;
  line-height: 1.6;
  margin-top: 10px;
}

.user-msg {
  color: #409EFF;
  margin: 8px 0;
}

.ai-msg {
  background: #f5f7fa;
  padding: 10px;
  border-radius: 4px;
  margin: 8px 0;
  color: red;
}
}
</style>

